package cn.edu.hust.youth.tzb.service;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

/**
 * <p>Title: </p>
 *
 * <p>Description: sztz</p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: hust</p>
 *
 * @author xy
 * @version 1.0
 */


public class EncodingFilter extends HttpServlet implements Filter {
    private FilterConfig filterConfig;
    //Handle the passed-in FilterConfig
    public void init(FilterConfig filterConfig) throws ServletException {
        this.filterConfig = filterConfig;
    }

    //Process the request/response pair
    public void doFilter(ServletRequest request, ServletResponse response,
                         FilterChain filterChain) {
        try {
            request.setCharacterEncoding("gbk");
            HttpServletResponse hresponse = (HttpServletResponse)response;
            hresponse.setHeader("Cache-Control","no-store");
            hresponse.setHeader("Pragma","no-cache");
            hresponse.setDateHeader("Expires",0);
            filterChain.doFilter(request, hresponse);
        } catch (ServletException sx) {
            filterConfig.getServletContext().log(sx.getMessage());
        } catch (IOException iox) {
            filterConfig.getServletContext().log(iox.getMessage());
        }
    }

    //Clean up resources
    public void destroy() {
    }
}
